package tests.create;

import static org.junit.Assert.*;

import model.BridgeHelper;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.workplicity.task.NetTask;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

/*
 * 
 * Logins in to Mongo
 * 
 */

public class LoginTest00
{

    /**
     * Default constructor
     */
    public LoginTest00()
    {
    }

    /**
     * Runs test setup processes.
     * @throws Exception
     */
    @BeforeClass
    public static void setUpClass() throws Exception
    {
    }

    /**
     * Runs test tear down processes.
     * @throws Exception
     */
    @AfterClass
    public static void tearDownClass() throws Exception
    {
    }

    /**
     * This is the main test method which just tries to login
     * with the default admin credentials.
     */
     @Test
     public void test()
     {
         // Get a context
         WorkletContext context = WorkletContext.getInstance();

         try
         {
             // Set the store name which is the mongo database
             NetTask.setStoreName("cc");
             BridgeHelper.getHamper().clear();
             
             // Output the base url which for testing should be
             // localhost:8080
             System.out.println("REST url = " + NetTask.getUrlBase());

             // Attempt the login -- by default this goes to the
             // Accounts collection
             Boolean successful = Helper.login("admin", "gaze11e", context);

             // If the login was not successful it's usually because...
             // 1) server is not up
             // 2) mongo-props misconfigured
             // Check these if successful is false
             if(!successful)
                 fail("Login failed");
             else
            	 System.out.println("Login successful");

             // If we get here without fail...the test was successful.
         }
         catch(Exception e)
         {
             fail("Login failed with exception: " + e);
         }
     }
}